package com.lxb.myforum.repository

import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.stereotype.Repository

import com.lxb.myforum.pojo.Dictionary

@Repository("dictRepository")
interface DictionaryRepository : PagingAndSortingRepository<Dictionary, Long>, JpaSpecificationExecutor<Dictionary> {

    @Query(value = "select max(code) from `t_dict` a where a.p_id = ?1", nativeQuery = true)
    fun findMaxCodeByPId(pId: Long?): String

    fun findByParentId(parentId: Long?): List<Dictionary>

    @Modifying
    @Query(value = "delete from t_dict where p_id = ?1", nativeQuery = true)
    fun deleteByPId(parentId: Long?)
}
